<adonisControls:AdonisWindow x:Class="FModel.Views.SearchView"
                             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                             xmlns:converters="clr-namespace:FModel.Views.Resources.Converters"
                             xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
                             xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI"
                             xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI"
                             WindowStartupLocation="CenterScreen" ResizeMode="CanResize" ShowInTaskbar="True"
                             IconVisibility="Collapsed" KeyDown="OnWindowKeyDown" StateChanged="OnStateChanged"
                             Height="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenHeight}, Converter={converters:RatioConverter}, ConverterParameter='0.75'}"
                             Width="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={converters:RatioConverter}, ConverterParameter='0.65'}">
    <adonisControls:AdonisWindow.Style>
        <Style TargetType="adonisControls:AdonisWindow" BasedOn="{StaticResource {x:Type adonisControls:AdonisWindow}}" >
            <Setter Property="Title" Value="搜索视图" />
        </Style>
    </adonisControls:AdonisWindow.Style>
    <adonisControls:AdonisWindow.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/Resources.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </adonisControls:AdonisWindow.Resources>
    <Grid Margin="5 5">
        <GroupBox adonisExtensions:LayerExtension.Layer="2" Padding="{adonisUi:Space 0}" Background="Transparent">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <Grid Grid.Row="0" Margin="0 0 0 5" ZIndex="0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <Grid Grid.Column="0" ZIndex="1" HorizontalAlignment="Left" Margin="5 2 0 0">
                        <Viewbox Width="16" Height="16">
                            <Canvas Width="24" Height="24">
                                <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource SearchIcon}" />
                            </Canvas>
                        </Viewbox>
                    </Grid>
                    <TextBox x:Name="WpfSuckMyDick" Grid.Column="0" Grid.ColumnSpan="2" Padding="25 0 0 0"
                             AcceptsTab="False" AcceptsReturn="False">
                        <TextBox.Style>
                            <Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
                                <Setter Property="Text" Value="{Binding CUE4Parse.SearchVm.FilterText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                                <Setter Property="adonisExtensions:WatermarkExtension.Watermark" Value="写入您的模式并按回车键..." />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding CUE4Parse.SearchVm.HasRegexEnabled}" Value="True">
                                        <Setter Property="adonisExtensions:WatermarkExtension.Watermark" Value="写入正则表达式模式并按回车键..." />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBox.Style>
                    </TextBox>
                    <StackPanel Grid.Column="1" Orientation="Horizontal">
                        <ToggleButton ToolTip="区分大小写" Padding="5" IsChecked="{Binding CUE4Parse.SearchVm.HasMatchCaseEnabled}" Style="{DynamicResource {x:Static adonisUi:Styles.ToolbarToggleButton}}">
                            <Viewbox Width="16" Height="16" HorizontalAlignment="Center">
                                <Canvas Width="24" Height="24">
                                    <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource MatchCaseIcon}" />
                                </Canvas>
                            </Viewbox>
                        </ToggleButton>
                        <ToggleButton ToolTip="正则表达式" Padding="5" IsChecked="{Binding CUE4Parse.SearchVm.HasRegexEnabled}" Style="{DynamicResource {x:Static adonisUi:Styles.ToolbarToggleButton}}">
                            <Viewbox Width="16" Height="16" HorizontalAlignment="Center">
                                <Canvas Width="24" Height="24">
                                    <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource RegexIcon}" />
                                </Canvas>
                            </Viewbox>
                        </ToggleButton>
                        <Button ToolTip="按文件大小排序" Padding="5" Style="{DynamicResource {x:Static adonisUi:Styles.ToolbarButton}}" Click="OnSortClick">
                            <Viewbox Width="16" Height="16" HorizontalAlignment="Center">
                                <Canvas Width="24" Height="24">
                                    <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource SortIcon}" />
                                </Canvas>
                            </Viewbox>
                        </Button>
                        <Button ToolTip="清除搜索过滤器" Padding="5" Style="{DynamicResource {x:Static adonisUi:Styles.ToolbarButton}}" Click="OnDeleteSearchClick">
                            <Viewbox Width="16" Height="16" HorizontalAlignment="Center">
                                <Canvas Width="24" Height="24">
                                    <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource BackspaceIcon}"/>
                                </Canvas>
                            </Viewbox>
                        </Button>
                    </StackPanel>
                    <TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="10 0 0 0" FontStyle="Italic">
                        <TextBlock.Text>
                            <MultiBinding StringFormat="{}{0:### ### ###}已加载的包({1})">
                                <Binding Path="CUE4Parse.SearchVm.ResultsCount" FallbackValue="0" />
                                <Binding Path="CUE4Parse.SearchVm.CurrentSortSizeMode" FallbackValue="None" />
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </Grid>

                <ListView Grid.Row="1" x:Name="SearchListView"
                          VirtualizingPanel.IsVirtualizing="True"
                          VirtualizingPanel.VirtualizationMode="Recycling"
                          ScrollViewer.CanContentScroll="True"
                          ItemsSource="{Binding CUE4Parse.SearchVm.SearchResultsView, IsAsync=True}">
                    <ListView.Resources>
                        <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                            <EventSetter Event="MouseDoubleClick" Handler="OnAssetDoubleClick" />
                        </Style>
                    </ListView.Resources>
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Width="900" Header="路径" adonisExtensions:GridViewSortExtension.PropertyName="Path">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock HorizontalAlignment="Left" Text="{Binding Path}" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="225" Header="档案" adonisExtensions:GridViewSortExtension.PropertyName="Archive">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock HorizontalAlignment="Left" Text="{Binding Vfs.Name}" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Width="100" Header="大小" adonisExtensions:GridViewSortExtension.PropertyName="Size">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock HorizontalAlignment="Right" Text="{Binding Size, Converter={x:Static converters:SizeToStringConverter.Instance}}" Margin="0 0 15 0" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                    <ListView.Style>
                        <Style TargetType="ListView" BasedOn="{StaticResource {x:Type ListView}}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding CUE4Parse.SearchVm.SearchResultsView.Count}" Value="0">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate>
                                                <Grid>
                                                    <TextBlock Text="在档案中找不到文件夹，请确保您至少加载了一个" FontWeight="SemiBold" TextAlignment="Center"
                                                               Foreground="{DynamicResource {x:Static adonisUi:Brushes.ErrorBrush}}" Margin="0 10 0 0" />
                                                </Grid>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </ListView.Style>
                    <ListView.ContextMenu>
                        <ContextMenu DataContext="{Binding PlacementTarget, RelativeSource={RelativeSource Self}}">
                            <MenuItem Header="跳转" Click="OnAssetDoubleClick">
                                <MenuItem.Icon>
                                    <Viewbox Width="16" Height="16">
                                        <Canvas Width="24" Height="24">
                                            <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource GoToIcon}" />
                                        </Canvas>
                                    </Viewbox>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="在新选项卡中提取" Click="OnAssetExtract">
                                <MenuItem.Icon>
                                    <Viewbox Width="16" Height="16">
                                        <Canvas Width="24" Height="24">
                                            <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource ExtractIcon}" />
                                        </Canvas>
                                    </Viewbox>
                                </MenuItem.Icon>
                            </MenuItem>
                            <Separator />
                            <MenuItem Command="{Binding DataContext.RightClickMenuCommand}">
                                <MenuItem.Header>
                                    <TextBlock
                                        Text="{Binding DataContext.SelectedItem.Extension,
                                                        FallbackValue='导出原始数据',
                                                        StringFormat='导出原始数据(.{0})',
                                                        RelativeSource={RelativeSource AncestorType=ContextMenu}}" />
                                </MenuItem.Header>
                                <MenuItem.CommandParameter>
                                    <MultiBinding Converter="{x:Static converters:MultiParameterConverter.Instance}">
                                        <Binding Source="Assets_Export_Data" />
                                        <Binding Path="SelectedItems" />
                                    </MultiBinding>
                                </MenuItem.CommandParameter>
                                <MenuItem.Icon>
                                    <Viewbox Width="16" Height="16">
                                        <Canvas Width="24" Height="24">
                                            <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource ExportIcon}" />
                                        </Canvas>
                                    </Viewbox>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="保存属性(.json)" Command="{Binding DataContext.RightClickMenuCommand}">
                                <MenuItem.CommandParameter>
                                    <MultiBinding Converter="{x:Static converters:MultiParameterConverter.Instance}">
                                        <Binding Source="Assets_Save_Properties" />
                                        <Binding Path="SelectedItems" />
                                    </MultiBinding>
                                </MenuItem.CommandParameter>
                                <MenuItem.Icon>
                                    <Viewbox Width="16" Height="16">
                                        <Canvas Width="24" Height="24">
                                            <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource SaveIcon}" />
                                        </Canvas>
                                    </Viewbox>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="保存纹理" Command="{Binding DataContext.RightClickMenuCommand}">
                                <MenuItem.CommandParameter>
                                    <MultiBinding Converter="{x:Static converters:MultiParameterConverter.Instance}">
                                        <Binding Source="Assets_Save_Textures" />
                                        <Binding Path="SelectedItems" />
                                    </MultiBinding>
                                </MenuItem.CommandParameter>
                                <MenuItem.Icon>
                                    <Viewbox Width="16" Height="16">
                                        <Canvas Width="24" Height="24">
                                            <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource TextureIcon}" />
                                        </Canvas>
                                    </Viewbox>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="保存模型" Command="{Binding DataContext.RightClickMenuCommand}">
                                <MenuItem.CommandParameter>
                                    <MultiBinding Converter="{x:Static converters:MultiParameterConverter.Instance}">
                                        <Binding Source="Assets_Save_Models" />
                                        <Binding Path="SelectedItems" />
                                    </MultiBinding>
                                </MenuItem.CommandParameter>
                                <MenuItem.Icon>
                                    <Viewbox Width="16" Height="16">
                                        <Canvas Width="24" Height="24">
                                            <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource ModelIcon}" />
                                        </Canvas>
                                    </Viewbox>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="保存动画" Command="{Binding DataContext.RightClickMenuCommand}">
                                <MenuItem.CommandParameter>
                                    <MultiBinding Converter="{x:Static converters:MultiParameterConverter.Instance}">
                                        <Binding Source="Assets_Save_Animations" />
                                        <Binding Path="SelectedItems" />
                                    </MultiBinding>
                                </MenuItem.CommandParameter>
                                <MenuItem.Icon>
                                    <Viewbox Width="16" Height="16">
                                        <Canvas Width="24" Height="24">
                                            <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource AnimationIcon}" />
                                        </Canvas>
                                    </Viewbox>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="保存音频" Command="{Binding DataContext.RightClickMenuCommand}">
                                <MenuItem.CommandParameter>
                                    <MultiBinding Converter="{x:Static converters:MultiParameterConverter.Instance}">
                                        <Binding Source="Assets_Save_Audio" />
                                        <Binding Path="SelectedItems" />
                                    </MultiBinding>
                                </MenuItem.CommandParameter>
                                <MenuItem.Icon>
                                    <Viewbox Width="16" Height="16">
                                        <Canvas Width="24" Height="24">
                                            <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource AudioIcon}" />
                                        </Canvas>
                                    </Viewbox>
                                </MenuItem.Icon>
                            </MenuItem>
                            <Separator />
                            <MenuItem Header="复制">
                                <MenuItem.Icon>
                                    <Viewbox Width="16" Height="16">
                                        <Canvas Width="24" Height="24">
                                            <Path Fill="{DynamicResource {x:Static adonisUi:Brushes.ForegroundBrush}}" Data="{StaticResource CopyIcon}" />
                                        </Canvas>
                                    </Viewbox>
                                </MenuItem.Icon>
                                <MenuItem Header="包路径" Command="{Binding DataContext.CopyCommand}">
                                    <MenuItem.CommandParameter>
                                        <MultiBinding Converter="{x:Static converters:MultiParameterConverter.Instance}">
                                            <Binding Source="File_Path" />
                                            <Binding Path="SelectedItems" />
                                        </MultiBinding>
                                    </MenuItem.CommandParameter>
                                </MenuItem>
                                <MenuItem Header="包名称" Command="{Binding DataContext.CopyCommand}">
                                    <MenuItem.CommandParameter>
                                        <MultiBinding Converter="{x:Static converters:MultiParameterConverter.Instance}">
                                            <Binding Source="File_Name" />
                                            <Binding Path="SelectedItems" />
                                        </MultiBinding>
                                    </MenuItem.CommandParameter>
                                </MenuItem>
                                <MenuItem Header="目录路径" Command="{Binding DataContext.CopyCommand}">
                                    <MenuItem.CommandParameter>
                                        <MultiBinding Converter="{x:Static converters:MultiParameterConverter.Instance}">
                                            <Binding Source="Directory_Path" />
                                            <Binding Path="SelectedItems" />
                                        </MultiBinding>
                                    </MenuItem.CommandParameter>
                                </MenuItem>
                                <MenuItem Header="带扩展名的包路径" Command="{Binding DataContext.CopyCommand}">
                                    <MenuItem.CommandParameter>
                                        <MultiBinding Converter="{x:Static converters:MultiParameterConverter.Instance}">
                                            <Binding Source="File_Path_No_Extension" />
                                            <Binding Path="SelectedItems" />
                                        </MultiBinding>
                                    </MenuItem.CommandParameter>
                                </MenuItem>
                                <MenuItem Header="带扩展名的包名称" Command="{Binding DataContext.CopyCommand}">
                                    <MenuItem.CommandParameter>
                                        <MultiBinding Converter="{x:Static converters:MultiParameterConverter.Instance}">
                                            <Binding Source="File_Name_No_Extension" />
                                            <Binding Path="SelectedItems" />
                                        </MultiBinding>
                                    </MenuItem.CommandParameter>
                                </MenuItem>
                            </MenuItem>
                        </ContextMenu>
                    </ListView.ContextMenu>
                </ListView>
            </Grid>
        </GroupBox>
    </Grid>
</adonisControls:AdonisWindow>